#!/bin/bash
files=(
    "https://physionet.org/files/mimiciii/1.4/ADMISSIONS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/CHARTEVENTS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/D_ICD_DIAGNOSES.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/D_ICD_PROCEDURES.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/D_ITEMS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/D_LABITEMS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/DIAGNOSES_ICD.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/ICUSTAYS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/LABEVENTS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/NOTEEVENTS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/OUTPUTEVENTS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/PATIENTS.csv.gz?download"

    "https://physionet.org/files/mimiciii/1.4/CALLOUT.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/CAREGIVERS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/CPTEVENTS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/DATETIMEEVENTS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/DRGCODES.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/D_CPT.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/D_LABITEMS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/INPUTEVENTS_CV.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/INPUTEVENTS_MV.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/MICROBIOLOGYEVENTS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/PRESCRIPTIONS.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/PROCEDUREEVENTS_MV.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/PROCEDURES_ICD.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/SERVICES.csv.gz?download"
    "https://physionet.org/files/mimiciii/1.4/TRANSFERS.csv.gz?download"
)

cookie="_ga=GA1.1.905993985.1706010022;_ga_YKC8ZQQ4FF=GS1.1.1717760785.10.1.1717760812.0.0.0;_gid=GA1.2.177511401.1717760787;csrftoken=dwGrFTZUa8C6g8s9DvCsSbF3yo2DpGwH;sessionid=uptsf5izmktnts3cxev4bvo63i79ydlr;"

for file in ${files[@]}; do
    filename=`echo $file | awk -F'/' '{print $NF}' | awk -F'?' '{print $1}'`
    curl -b "$cookie" -L -o $filename $file -#
done

# for file in `ls *.gz`; do
#     gunzip $file
# done
